﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using FluentTags;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        FluentTags.TableTag t = new FluentTags.TableTag()
            .TR()
                .TH("1st column")
                    .Img().Src("~/img/up.png").Alt("Sort Asc").End()
                .End()
                .TH("2nd column")
                    .Img().Src("~/img/down.png").Alt("Sort Desc").End()
                .End().End()
            .TR()
                .TH("1st column").End().TH("2nd column").End().End()
            .TR()
                .TD("Test").End().TD(DateTime.Now.ToString()).End().End()
             .TR()
                .TD("5").End().TD("false").End().End()
             .TR()
                .TD("----- This td should be 2 columsn wide --------").Colspan(2).End().End()
            .TR()
                .TD().Text("10").End().TD().Text("false").End().End()
            .TR()
                .TH("This should be bold red").Class("BoldRed").End().TH("this should be blue").Class("Blue").End().End()
            .TR()
                .TH("This should be bold green").Style("font-style:bold;color:Green;").End()
                .TH("grey, right aligned").Style("text-align:right;color:Gray;").End().End()
            .TR()
                .TD("Test").End().TD(DateTime.Now.ToString()).End().End()
            .TR()
                .TD().A().Href("http://intranet/").Text("Intranet").End().End()
                .TD()
                    .A().Href("http://intranet/").Text("Intranet")
                        .Title("teh intarwebs")
                    .End()
                .End()
            .End()
            .TR()
                .TD().Img().Src("~/img/up.png").Alt("Move Up").End().End()
                .TD().Img().Src("~/img/down.png").Alt("Move Down").End().End()
            .End()
            .TR()
                .TD().A().Href("~/").Img().Src("~/img/up.png").Alt("Move Up").End().End().End()
                .TD().A().Href("~/").Img().Src("~/img/down.png").Alt("Move Down").End().End().End()
            .End()
            .TR()
                .TD().A().Href("~/").Img().Src("~/img/up.png").Alt("Move Up").End().Text("Move Up").End().End()
                .TD().A().Href("~/").Img().Src("~/img/down.png").Alt("Move Down").End().Text("Move Down").End().End()
            .End()
        ;

        Button b = new Button();
        b.Text = "This Causes a postback";
        b.Click += (s, evt) =>
        {
            DivPlaceHolder.Controls.Add(new DivTag().Text("The button postback Worked!").Style("color:red;").End());

        };

        Button b2 = new Button();
        b2.Text = "This Causes a postback";
        b2.Click += (s, evt) =>
        {
            DivPlaceHolder.Controls.Add(new DivTag().Text("The button2 postback Worked!").Style("color:red;").End());

        };

        t.TR()
            .TD().AddControl(b).End()
            .TD().AddControl(b2).End()
        .End();

        TablePlaceHolder.Controls.Add(t);

        FluentTags.DivTag d = new FluentTags.DivTag("This should be in a div")
            .Div(8).End()
            .Div("This is inside a child div of the root div")
            .Div(DateTime.Now.ToString()).End().End();
        DivPlaceHolder.Controls.Add(d);


        var div = new DivTag();
        var table = div.Table().Style("text-align:center;");
        table.TR()
            .TD(RenderNavFirst(""))
            .TD("test").End();

        DivPlaceHolder.Controls.Add(div);

    }

    private TDTag RenderNavFirst(string style)
    {
        return new TDTag().Style(style).A().Href("~").Text("<< First").End();
    }
    
}
